#ifndef __BASIC_MSGQ_H__
#define __BASIC_MSGQ_H__

#include <basic/misc.h>

__BEGIN_DECLS

#define MSGQ_QUEUES_MAX             500
#define MSGQ_MSG_MAX                200
#define MSGQ_MSGSIZE_MAX            KB(1024-1)

struct _msgq_send;
typedef struct _msgq_send *MSGQ_SEND;
struct _msgq_recv;
typedef struct _msgq_recv *MSGQ_RECV;

extern int
msgq_send_attach(
        MSGQ_SEND *p_msgq
        );

extern int
msgq_send_detach(
        MSGQ_SEND msgq
        );

extern int
msgq_send(
        MSGQ_SEND msgq,
        char *from,
        char *to,
        unsigned int syn,
        unsigned char *msg,
        int msg_size,
        int timeout_ms);

extern int
msgq_recv_attach(
        char *queue_name,
        MSGQ_RECV *p_msgq
        );

extern int
msgq_recv_detach(
        MSGQ_RECV msgq
        );

extern int
msgq_recv(
        MSGQ_RECV msgq,
        char *from, 
        unsigned int *syn,
        unsigned char *msg,
        int *msg_size,
        int timeout_ms
        );

extern int
msgq_clear(
        char *queue_name
        );

struct _msgq_syn;
typedef struct _msgq_syn *MSGQ_SYN;

/*
 * 连入同步消息队列
 */
extern int
msgq_syn_attach(
        char *recv_queue_name,
        MSGQ_SYN *msgqp
        );

/*
 * 脱离同步消息队列
 */
extern int
msgq_syn_detach(
        MSGQ_SYN msgq
        );

/*
 * 客户端通过同步消息队列调用服务
 */
extern int
msgq_syn_call(
        MSGQ_SYN msgq,
        char *send_queue_name,
        unsigned char *request,
        int request_size,
        unsigned char *respond,
        int *respond_size,
        int timeout_ms
        );

/*
 * 服务端通过同步消息队列接受请求
 */
extern int
msgq_syn_fetch(
        MSGQ_SYN msgq,
        unsigned char *msg,
        int *msg_size,
        int timeout_ms
        );

/*
 * 服务端通过同步消息队列发送应答
 */
extern int
msgq_syn_reply(
        MSGQ_SYN msgq,
        unsigned char *msg,
        int msg_size,
        int timeout_ms
        );

__END_DECLS

#endif
